﻿using NfsCommon.Util;
using NfsModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NfsBLL
{
    /// <summary>
    /// account
    /// </summary>
    public partial class AccountBLL
    {
        private readonly NfsDAL.AccountDAL dal = new NfsDAL.AccountDAL();
        public AccountBLL()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(NfsModel.account model, out int id)
        {
            return dal.Add(model, out id);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(NfsModel.account model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return dal.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return dal.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public NfsModel.account GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public NfsModel.account GetModelByCache(int id)
        {

            string CacheKey = "accountModel-" + id;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(id);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (NfsModel.account)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<NfsModel.account> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<NfsModel.account> DataTableToList(DataTable dt)
        {
            List<NfsModel.account> modelList = new List<NfsModel.account>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                NfsModel.account model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = dal.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  BasicMethod
        #region  ExtensionMethod
        #region 登录
        public account GetLogin(string userName, string userPwd)
        {
            return dal.GetLogin(userName, userPwd);
        }
        #endregion

        #region 修改密码
        public bool UptPassword(int id, string pwd)
        {
            return dal.UptPassword(id, pwd);
        }
        #endregion
        #region 查询修改密码时输入的旧密码是否与数据库的相匹配
        public bool GetPassword(int id, string pwd)
        {
            return dal.GetPassword(id, pwd);
        }
        #endregion
        #region PC模糊查询
        public List<account> GetAccountBycondtion(int pageindex, int pagesize, string Name, string mobile,int type)
        {
            DataTable dt = dal.GetAccountBycondtion(pageindex, pagesize, Name, mobile,type);
            return ConverToExcs.ConvertToEx<account>(dt);
        }
        public object GetAccountBycondtionCount(string Name, string mobile)
        {
            return dal.GetAccountBycondtionCount(Name, mobile);
        }
        #endregion
        #endregion  ExtensionMethod
        #region 删除(逻辑删除)全局共用
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="tabName">表名</param>
        /// <param name="name">字段</param>
        /// <param name="valid">值</param>
        /// <returns></returns>
        public bool com_delelte(int id, string tabName, string name, int valid)
        {
            return dal.com_delelte(id, tabName, name, valid);
        }
        #endregion
    }
}

